﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.echonest.api.v4;
using jENIKVMApi;

namespace RequestEchoNest.Data
{
    public class SimilarSongSpecification
    {

        //track.getTitle()
        //track.getArtistName()
        //track.getKey()

        //analysys.getDuration()
        //

        //analysys.getLoudness()
        //analysys.getTimeSignature()
        //analysys.GetBars()
        // analysys.GetBeats()
        //analysys.GetTatums()
        //analysys.GetSections()                        
        //analysys.GetSegments()

        public static SongParams Create(Track track)
        {
            var p = new SongParams();
            TrackAnalysis analysys = track.getAnalysis();

            //var duration = analysys.getDuration().ToDouble();
            //var minDuration = duration / 2;
            //var maxDuration = duration * 2 > 60 ? duration * 2 : 60;
            //p.setMaxDuration((float)maxDuration);
            //p.setMinDuration((float)minDuration);
            //p.setMaxDuration(1);

            //var tempo = analysys.getTempo().ToDouble();
            //var maxTempo = tempo * 2;
            //var minTempo = tempo / 2;
            //p.setMaxTempo((float)maxTempo);
            //p.setMinTempo((float)minTempo);

            var title = track.getTitle();
            if (!String.IsNullOrWhiteSpace(title))
            p.setTitle(title);

            var artist = track.getArtistName();
            if (!String.IsNullOrWhiteSpace(artist))
                p.setArtist(artist);

            //var loudness = track.getLoudness();
            //var maxLoudness = loudness + 40 > 100 ? 100 : loudness + 20;
            //var minLoudness = loudness - 40 < -100 ? -100 : loudness - 20;
            //p.setMaxLoudness((float)maxLoudness);
            //p.setMinLoudness((float)minLoudness);

            
            var segments = analysys.GetSegments();
            //var sumMaxLoudness = 0;
            //var counter = 0;
            //foreach (var segment in segments)
            //{sumMaxLoudness+=segment.get
            //    counter++;
            //}
            
            //p.setMaxEnergy();

            //p.setMaxDanceability();

            // will not use because Earth location related (are title and artist name connected)
            //p.setMaxLatitude();
            //p.setMaxLongitude();

            // cannon use next
            //http://developer.echonest.com/forums/thread/463
            //p.setMaxSongHotttnesss();
            //sp.setMaxArtistFamiliarity();
            //sp.setMaxArtistHotttnesss();

            return p;
        }





    }
}
